package com.hirsi.module.department.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.hirsi.module.department.service.DepartmentService;
import com.hirsi.module.department.vo.EditDepartmentVo;
import com.hirsi.module.department.vo.param.MoveDepartmentParam;
import com.hirsi.module.department.vo.param.RemoveMemberParam;
import com.hirsi.module.department.vo.result.DepartmentTreeResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "部门管理")
@ApiSupport(order = 3)
@RestController
@RequestMapping("v1/department")
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;

    @ApiOperation("查询部门结构树")
    @ApiOperationSupport(order = 1)
    @GetMapping("tree")
    public List<DepartmentTreeResult> tree() {
        return departmentService.tree();
    }

    @ApiOperation("编辑回显部门")
    @ApiOperationSupport(order = 2)
    @GetMapping("edit")
    public EditDepartmentVo edit(@ApiParam(value = "部门id", required = true) @RequestParam Integer id) {
        return departmentService.edit(id);
    }

    @ApiOperation("保存部门")
    @ApiOperationSupport(order = 3)
    @PostMapping("save")
    public void save(@RequestBody EditDepartmentVo vo) {
        departmentService.save(vo);
    }

    @ApiOperation("移动部门(交换部门位置)")
    @ApiOperationSupport(order = 4)
    @PostMapping("move")
    public void move(@RequestBody MoveDepartmentParam param) {
        departmentService.move(param);
    }

    @ApiOperation("删除部门")
    @ApiOperationSupport(order = 5)
    @PostMapping("delete")
    public void delete(@RequestBody List<Integer> ids) {
        departmentService.delete(ids);
    }

    @ApiOperation("移除部门成员")
    @ApiOperationSupport(order = 6)
    @PostMapping("remove_member")
    public void removeMember(@RequestBody RemoveMemberParam param) {
        departmentService.removeMember(param);
    }
}
